package com.qf.service.impl;

import com.qf.dao.CartDao;
import com.qf.dao.GoodsDao;
import com.qf.pojo.Cart;
import com.qf.pojo.Goods;
import com.qf.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author bss
 * @version V1.0
 * @Project maven
 * @Package com.qf.service.impl
 * @Description:
 * @Date 2022/10/3 14:57
 */
@Service
public class CartServiceImpl implements CartService {

    @Autowired
    CartDao cartDao;
    @Autowired
    GoodsDao goodsDao;

    @Override
    public void add(Cart cart) {
        cartDao.addCart(cart);
    }

    @Override
    public void update(Cart cart) {
        cartDao.updateCart(cart);
    }

    @Override
    public Cart checkCartByIdAndPid(int uid, int goodId) {
        Cart cart = cartDao.selectByIdAndGoodId(uid, goodId);
        return cart;
    }

    @Override
    public List<Cart> findByUid(int id) {
        List<Cart> card = cartDao.getCardById(id);
        for (Cart cart : card) {
            Goods good = goodsDao.findById(cart.getPid());
            cart.setGoods(good);
        }
        return card;
    }

    @Override
    public void deleteGood(int id, int pid) {
        cartDao.deleteGood(id,pid);
    }

    @Override
    public void clearCart(int id) {
        cartDao.clearCart(id);
    }
}
